#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int f = 0, ans = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void printws(int x, char ch = ' ')
{
    write(x);
    putchar(ch);
}
inline void println(int x)
{
    write(x);
    putchar('\n');
}
constexpr int N = 1e5 + 5, SIZE = (4 * (1 + 4)) >> 1;
int n, K, a[N];
int cnt[N], ap[N];
inline int check()
{
    for (int i = 1; i <= K; ++i)
        if (!ap[i])
            return 0;
    return 1;
}
signed main()
{
    freopen("reporter.in", "r", stdin);
    freopen("reporter.out", "w", stdout);
    n = read(), K = read();
    if (K == 1)
    {
        println((n * (n + 1)) >> 1);
        return 0;
    }
    for (int i = 1; i <= n; ++i)
        a[i] = read();
    int res = 0;
    if (*max_element(a + 1, a + n + 1) <= K)
    {
        for (int i = 1; i <= n; ++i)
        {
            int lim = min(i + SIZE, n);
            for (int j = i; j <= lim; ++j)
            {
                if (cnt[a[j]])
                    --ap[cnt[a[j]]];
                ++ap[++cnt[a[j]]];
                res += check();
            }
            for (int j = i; j <= lim; ++j)
                cnt[a[j]] = 0;
            for (int i = 1; i <= SIZE; ++i)
                ap[i] = 0;
        }
    }
    else
        for (int i = 1; i <= n; ++i)
        {
            fill(ap + 1, ap + n + 1, 0);
            fill(cnt + 1, cnt + n + 1, 0);
            for (int j = i; j <= n; ++j)
            {
                if (cnt[a[j]])
                    --ap[cnt[a[j]]];
                ++ap[++cnt[a[j]]];
                res += check();
            }
        }
    println(res);
    return 0;
}